package multidraw.tools;

import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import multidraw.DrawingCanvasView;
import multidraw.model.DrawingCanvasModel;
import multidraw.model.Shape;
import multidraw.model.TextBox;
import multidraw.model.commands.AddCharCommand;
import multidraw.model.commands.AddShapeCommand;
import multidraw.model.commands.WrapperCommand;



public class TextBoxTool extends Tool {
	private TextBoxFactory factory;
	private TextBox shape;
	//private DrawingCanvasModel myModel;
	
	/**
	 * we need a view to the canvas to get the focus
	 * in order to receive key stroke.
	 */
	private DrawingCanvasView myView;
	
	public TextBoxTool(DrawingCanvasModel model, DrawingCanvasView view, TextBoxFactory factory) {
		this.myModel = model;
		this.factory = factory;
		this.myView = view;
	}
	
	public void mouseClicked(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		myView.requestFocus();
		shape = factory.createTextBox(myModel.getPenColor(), arg0.getPoint(), 
				myModel.getNextID());
		//myModel.addShape(shape);
		AddShapeCommand cmd = new AddShapeCommand(shape, myModel.getRevisionID() + 1);
		try {
			WrapperCommand wrapCmd = new WrapperCommand(cmd);
			myModel.addCommand(wrapCmd);
		} catch (Exception e1) {
			System.out.println(e1);
		}
	}
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void mouseDragged(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void mouseMoved(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public Shape getShape() {
		// TODO Auto-generated method stub
		return shape;
	}
	
	@Override
	public void keyTyped(KeyEvent e) {
		//shape.addChar(e.getKeyChar());
		AddCharCommand command = new AddCharCommand(shape.getShapeID(), e.getKeyChar());
		myModel.addCommand(command);
	}

}
